package GUI;

import item.TopSellingItem;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.LayoutManager;
import java.sql.Date;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import database.TableManager;
import database.TableManager.TableEnum;

public class GUI_page04_TopSellingItems extends JPanel {
	
	JLabel titleLabel;
	JButton returnButton;
	
	JLabel dateLabel;
	JTextField dateField;
	JLabel numItemsLabel;
	JTextField numItemsField;
	JButton submitButton;
	
	JTable table;
	JScrollPane scrollPane;
	
	TableManager tm;
	Date date;
	int numItems;

	public GUI_page04_TopSellingItems() {
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		this.setBackground(Color.white);
		// title label
		titleLabel = new JLabel("Top Selling Items", JLabel.CENTER);
		titleLabel.setVerticalTextPosition(JLabel.CENTER);
		
		titleLabel.setHorizontalTextPosition(JLabel.CENTER);
		titleLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
		titleLabel.setFont(new Font("Century Gothic", Font.BOLD, 20));
		titleLabel.setForeground(Color.gray);
        this.add(titleLabel);
        
        this.add(Box.createRigidArea(new Dimension(0,15)));

        // return button
        returnButton = GUI_AMSStoreMain.makeGrayWhiteButton("Back", Component.LEFT_ALIGNMENT);
        this.add(returnButton);
        
        this.add(Box.createRigidArea(new Dimension(0,15)));
        
        // date field
		dateLabel = GUI_AMSStoreMain.makeLeftAlignedGrayLabel("Current Date (yyyy-mm-dd)", 11);
		this.add(dateLabel);
		dateField = GUI_AMSStoreMain.makeLeftGrayTextField("yyyy-mm-dd", 80);
		this.add(dateField);
		
		this.add(Box.createRigidArea(new Dimension(0,5)));
		
		// number of items field
		numItemsLabel = GUI_AMSStoreMain.makeLeftAlignedGrayLabel("Number of Items to Display", 11);
		this.add(numItemsLabel);
		numItemsField = GUI_AMSStoreMain.makeLeftGrayTextField("",80);
		this.add(numItemsField);
		
		this.add(Box.createRigidArea(new Dimension(0,15)));

        // submit (generate list) button
        submitButton = GUI_AMSStoreMain.makeGrayWhiteButton("Generate List", Component.LEFT_ALIGNMENT);
        this.add(submitButton);
        
        this.add(Box.createRigidArea(new Dimension(0,15)));
        
        scrollPane = new JScrollPane(table);
		this.add(scrollPane);
	}
	
	public void populateTable(Object[] columnNames, Object[][] data){
		
		this.remove(scrollPane);
		
		if (columnNames == null || data == null)
			scrollPane = new JScrollPane();
		else
		{
			table = new JTable(data, columnNames);
			table.setPreferredScrollableViewportSize(new Dimension(400,70));
			table.setFillsViewportHeight(true);
			scrollPane = new JScrollPane(table);
		}
		this.add(scrollPane);
		
	}

}